<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" :title="title"></uni-navbar></view>

		<!-- <view class="search-view"><u-search class="search-input" @search="search" @custom="search"></u-search></view> -->

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-inner">
				<view class="list-info_08" v-for="(item, index) of newsList" :key="item.id" @click="navTo('/pagesB/xuexi/detail_video?id=' + item.id)">
					<view class="right">
						<image class="image" :src="linksImg(item.coverImg)" mode="aspectFill"></image>
						<!-- <view class="time">
							<u-icon name="play-right-fill" color="#fff" size="20"></u-icon>
							<text>10:25</text>
						</view> -->
					</view>
					<view class="left">
						<view class="info-title">{{ item.title }}</view>
						<view class="info-btm">
							<view class="name clamp">{{ item.author ? item.author : item.createByName }}</view>
							<text class="line"></text>
							<view class="time">{{ item.createTime }}</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<view class="btn-add" v-if="$sysBtns('zsxxwz_add')" @click="navTo('/pagesB/xuexi/add_video')">
			<u-icon name="plus" color="#fff" size="40"></u-icon>
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			tabsCurrent: 0,
			tabsList: [],
			colorMap: {
				0: '#0099ff',
				1: '#ff9900',
				2: '#19be6b'
			},
			nodeStatus: -1,
			title: '学习培训',
			newsList: [],

			news: {
				type: '3',
				secType: '',
				articleType: '',
				nodeStatus: '',
				clientCode: '',
				title: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option.type) {
			this.news.type = option.type;
		}
		if (option.secType) {
			this.news.secType = option.secType;
		}
		if (option.articleType) {
			this.news.articleType = option.articleType;
		}

		if (option.title) {
			this.title = option.title;
		}
		uni.setNavigationBarTitle({
			title: this.title
		});

		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (type == 'add' && this.loading == 'loading') {
				return false;
			}
			if (type == 'add' && this.loading == 'nomore') {
				return false;
			}

			this.loading = 'loading';
			if (type != 'add') {
				this.pageNum = 1;
			}
			let url = '/dushuxuexi/article/list';
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				userId: this.userId,
				...this.news
			};

			this.$request(url, data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.newsList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.newsList = this.newsList.concat(res.data.records);
				this.loaded = true;
				if (this.newsList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		search(e) {
			this.news.title = e;
			this.loadData('refresh');
		},
		type(e) {
			// this.nodeStatus = e;
			// this.news.nodeStatus = e || '';
			this.newsList = [];
			this.loadData('refresh');
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		linksImg(url) {
			if (url) {
				return this.$baseUrl + '/file/download/preview/0?path=' + url.replace(/\\/g, '/');
			} else {
				return this.$staticImgRandom('/static/img/default_big.png');
			}
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 20rpx 30rpx 0;
}

.list-inner {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
}
</style>
